
/**
 * 
 * 2021年7月22日16:40:00
 * author：coderWWH
 * 学习express框架
 * 
 */

const express = require('express')
const app = express()

const querystring = require('querystring')

app.listen(8888, () => {
  console.log('8888ok')
})

//路由重定向
app.get('/', (req, res) => {
  res.sendFile(__dirname + '/login.html')
})

app.get('/search', (req, res) => {
  res.send(req.url)
  console.log(req.query)
})

app.get('/login', (req, res) => {
  res.send('登录成功')
})

app.post('/login', (req, res) => {

  req.on('data', (chunk) => {
    //chunk传递一段数据
    console.log(chunk.toString())
    let str = chunk.toString()
    //转字符串后的格式为查询字符串，需要解析为对象
    let obj = querystring.parse(str)
    console.log(obj)
  })

  res.send('登录成功')
})

//路由传参
app.get('/package/:pname', (req, res) => {
  console.log(req.params)
  res.send('/package')
})

app.get('/shopping/:lid/:num', (req, res) => {
  console.log(req.params)
  res.send('/shopping')
})




